<template>
  <div>
    <template v-for="menu in menus[0].children" >
      <div class="menu-item" v-if="menu.children && menu.children.length" :key="menu.id">
        <h3 class="title">{{menu.meta.title}}</h3>
        <a-row :gutter="16" >
          <template v-for="item in menu.children">
            <a-col class="gutter-row" :xxl="5" :xl="7" :sm="10" v-if="!item.hidden" :key="item.id" >
              <div class="item" @click="handleJumpPath(item,menu)">
                <a-icon class="icon" :type="item.meta.icon" />
                <div class="text">
                  <div class="name">{{ item.meta.title }}</div>
                  <div class="desc">{{ item.meta.label }}</div>
                </div>
              </div>
            </a-col>
          </template>
        </a-row>
      </div>
    </template>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  components: {
  },
  data() {
    return {
    }
  },
  computed: {
    ...mapState({
      // 后台菜单
      menus: state => state.user.authPermissionList.filter(e => e.path == '/operate-tool'),
    })
  },
  created() {
    console.log(this.menus, 'menusxxxxx')
  },
  mounted() {},
  beforeDestroy() {},
  methods: {
    // 跳转的链接/路由
    handleJumpPath(menu,parent) {
      if (menu.meta.internalOrExternal) {
       this.getQueryLocationUrl(menu.id)
      }else if(menu.name.includes('http')){
        console.log(222)
        const path = `${parent.path}/${menu.path}`
        console.log(path)
        // iframe嵌入的菜单 
        this.$router.push(path)
      }
      else {
        console.log('else')
        this.$router.push(menu.path)
      }
    },

    //获取外部链接/安装包链接
    getQueryLocationUrl(id) {
      const data = {
        id
      }
      queryLocationUrl(data).then(res => {
        if (res.code === 0) {
          window.open(res.result, '_blank')
        } else {
          this.$message.error(res.data.msg)
        }
      })
    },
  }
}
</script>
<style lang="less" scoped>
/deep/ .ant-row{
  margin-left: 0 !important;
  margin-right: 0!important;
}
.menu-item{
  margin-bottom: 10px;
  .title{
    padding-left: 8px;
    line-height: 30px;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: bold;
  }
}
.item{
  margin-block: 8px;
  padding: 15px;
  background: #fff;
  border-radius: 10px;
  display: flex;
  cursor: pointer;
  .icon{
    width: 60px;
    height: 60px;
    line-height: 60px;
    border-radius: 7px;
    text-align: center;
    background: #e9ecef;
    vertical-align: middle;
    font-size: 24px;
  }
  .text{
    flex: 1;
    margin-left: 15px;
    overflow: hidden;
    .name{
      line-height: 30px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      word-break: break-all;
       /* autoprefixer: off */
      -webkit-box-orient: vertical;
      /* autoprefixer: on */
    }
    .desc {
      line-height: 30px;
      font-size: 12px;
      color: #a8a8a8;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      word-break: break-all;
       /* autoprefixer: off */
      -webkit-box-orient: vertical;
      /* autoprefixer: on */
    }
  }
}
</style>

